package com.da.web.dorm_into.controller;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.da.common.Result;
import com.da.web.dorm_into.entity.DormInto;
import com.da.web.dorm_into.entity.IntoParm;
import com.da.web.dorm_into.service.DormIntoService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * @author da
 * @time 2023/12/15 上午 10:12
 */
@RestController
@RequestMapping("/api/into")
public class DormIntoController {
    @Autowired
    private DormIntoService dormIntoService;

    //新增
    @PostMapping
    public Result add(@RequestBody DormInto dormInto) {
        boolean save = dormIntoService.save(dormInto);
        if (save) {
            return Result.success("新增成功");
        }
        return Result.error("新增失败");
    }

    //编辑
    @PutMapping
    public Result edit(@RequestBody DormInto dormInto) {
        boolean save = dormIntoService.updateById(dormInto);
        if (save) {
            return Result.success("编辑成功");
        }
        return Result.error("编辑失败");
    }

    //删除
    @DeleteMapping("/{intoId}")
    public Result delete(@PathVariable("intoId") Long intoId) {
        boolean save = dormIntoService.removeById(intoId);
        if (save) {
            return Result.success("删除成功");
        }
        return Result.error("删除失败");
    }

    //列表
    @GetMapping("/list")
    public Result list(IntoParm parm) {
        IPage<DormInto> list = dormIntoService.pageList(parm);
        return Result.success("查询成功", list);
    }

}
